package com.example.myapplication11_21;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.BubbleChart;
import com.github.mikephil.charting.data.BubbleData;

import com.github.mikephil.charting.data.BubbleDataSet;
import com.github.mikephil.charting.data.BubbleEntry;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        BubbleChart bubbleChart=findViewById(R.id.chart1);

        
        float[] f1={4.5f,6.0f,6.0f,5.3f,4.5f};
        float[] f2={5.3f,6.0f,6.0f,4.5f,5.5f};
        float[] f3={4.5f,3.0f,1.8f,0.8f,5.8f};

        List<IBubbleDataSet> s = new ArrayList<>();
        BubbleDataSet demo1=getDataSet(f1,"demo1");
        demo1.setColor(Color.parseColor("#CE0000"));
        s.add(demo1);

        BubbleDataSet demo2=getDataSet(f2,"demo2");
        demo2.setColor(Color.parseColor("#ff99ff"));
        s.add(demo2);

        BubbleDataSet demo3=getDataSet(f3,"demo3");
        demo3.setColor(Color.parseColor("#CA8EFF"));
        s.add(demo3);

        BubbleData data = new BubbleData(s);
        bubbleChart.setData(data);
        bubbleChart.invalidate();
    }
    private BubbleDataSet getDataSet(float[] f,String title){
        List<BubbleEntry> data=new ArrayList<>();
        for (int x=0;x<f.length;x++){
            BubbleEntry bubbleEntry=new BubbleEntry(x,f[x],x);
            data.add(bubbleEntry);
        }
        return new BubbleDataSet(data,title);
    }
}

